package com.uniriho.lxr0811_7300_bl.base

import java.util.Locale
import java.util.UUID

object Constant {
    @JvmField
    var BQID: String = ""

    @JvmField
    var BluConnectState: Boolean = false
    const val IPADRESS = "192.168.2.202"
    const val SERVERDATA_RE = 1001
    const val POINT = 2001
    const val BLUE_TOOTH_DIALOG = 0x111
    const val BLUE_TOOTH_TOAST = 0x123
    const val BLUE_TOOTH_WRAITE = 0X222
    const val BLUE_TOOTH_READ = 0X333
    const val BLUE_TOOTH_WRAITE_FILE_NOW = 0X511
    const val BLUE_TOOTH_READ_FILE_NOW = 0X996
    const val BLUE_TOOTH_WRAITE_FILE = 0X555
    const val BLUE_TOOTH_READ_FILE = 0X888
    const val BLUE_TOOTH_SUCCESS = 0x444

    /*与0811通信指令集*/
    /*系统模块*/
    //【获取设备CPUID】FF00FF000F010100000100010312FE
    val SYSTEM_CPUID = "FF00FF000F010100000100010312FE"

    //【获取固件版本】FF00FF000F01020000010001CDF2FE
    val SYSTEM_VS = "FF00FF000F01020000010001CDF2FE"

    // 【获取设备时间】FF00FF000F0105000001000105B3FE
    val SYSTEM_TIME = "FF00FF000F0105000001000105B3FE"

    // Psam卡模块
    // 【卡槽上电】FF00FF00100111000001000101CE93FE
    val PSAM_POWERON = "FF00FF00100111000001000101CE93FE"

    // 【卡槽下电】
    val PSAM_POWEROFF = ""

    // 【 卡复位  】FF00FF000F01120000010001D776FE
    val PSAM_RESET = "FF00FF000F01120000010001D776FE"

    // 【取随机数】FF00FF000F0113000001000192D6FE
    val PSAM_RAND = "FF00FF000F0113000001000192D6FE"

    // 【加密】FF00FF001F0114000001000111223344556677881122334455667788CCC0FE
    val PSAM_ENCRYPT = "FF00FF001F0114000001000111223344556677881122334455667788CCC0FE"

    // 【解密】FF00FF001F01150000010001973EA14E82A72CFAAEF8D34D7F6015C1FA1BFE
    val PSAM_DECRYPT = "FF00FF001F01150000010001973EA14E82A72CFAAEF8D34D7F6015C1FA1BFE"

    /* 指纹模块*/
    // 【上电】FF00FF001001200000010001012F7FFE
    val FINGERINPUT_POWERON = "FF00FF001001200000010001012F7FFE"

    // 【下电】FF00FF001001200000010001003F5EFE
    val FINGERINPUT_POWEROFF = "FF00FF001001200000010001003F5EFE"

    // 【版本】FF00FF000F01210000010001361AFE
    val FINGERINPUT_VS = "FF00FF000F01210000010001361AFE"

    // 【指纹采集】FF00FF000F01240000010001751BFE
    val FINGERINPUT_INPUT = "FF00FF000F01240000010001751BFE"

    // 【指纹比对】FF00FF000F01260000010001FE5BFE
    val FINGERINPUT_COMPARISON = "FF00FF000F01260000010001FE5BFE"

    // 【清空模板库】FF00FF000F01270000010001BBFBFE
    val FINGERINPUT_CLEAR = "FF00FF000F01270000010001BBFBFE"

    // 【读安全等级】FF00FF000F01220000010001F8FAFE
    val FINGERINPUT_READSECURITYLEVEL = "FF00FF000F01220000010001F8FAFE"

    // 【设安全等级】FF00FF00100123000001000103D7BFFE
    val FINGERINPUT_SETSECURITYLEVEL = "FF00FF00100123000001000103D7BFFE"

    /* LED模块*/
    // 【LED1开|关】FF00FF0011017100000100010100497FFE | FF00FF0011017100000100010101595EFE
    val LED1_OPEN = "FF00FF0011017100000100010100497FFE"
    val LED1_CLOSE = "FF00FF0011017100000100010101595EFE"

    // 【LED2开|关】FF00FF00110171000001000102001C2CFE | FF00FF00110171000001000102010C0DFE
    val LED2_OPEN = "FF00FF00110171000001000102001C2CFE"
    val LED2_CLOSE = "FF00FF00110171000001000102010C0DFE"

    // 【LED3开|关】FF00FF00110171000001000103002F1DFE | FF00FF00110171000001000103013F3CFE
    val LED3_OPEN = "FF00FF00110171000001000103002F1DFE"
    val LED3_CLOSE = "FF00FF00110171000001000103013F3CFE"

    // 【LED4开|关】FF00FF0011017100000100010400B68AFE | FF00FF0011017100000100010401A6ABFE
    val LED4_OPEN = "FF00FF0011017100000100010400B68AFE"
    val LED4_CLOSE = "FF00FF0011017100000100010401A6ABFE"

    //
    /* 超高频模块*/
    // 【获取版本】FF00FF000F014100000100016902FE
    val UHF_VS = "FF00FF000F014100000100016902FE"

    // 【寻卡】FF00FF000F01420000010001A7E2FE
    val UHF_FIND = "FF00FF000F01420000010001A7E2FE"

    // 【读卡】
    val UHF_READCARD = ""

    // 【写卡】
    val UHF_WRITECARD = ""

    // 【读功率】FF00FF000F014500000100016FA3FE
    val UHF_READPOWER = "FF00FF000F014500000100016FA3FE"

    // 【写功率】FF00FF0010014600000100011eDE9EFE
    val UHF_WRITEPOWER = "FF00FF0010014600000100011eDE9EFE"

    // 【读天线】FF00FF000F014900000100016440FE
    val UHF_READANTENNA = "FF00FF000F014900000100016440FE"

    // 【设天线】FF00FF000F015000000100016440FE
    val UHF_SETANTENNA = "FF00FF000F014A00000100016440FF"

    /* 语音*/
    // 【语音测试】FF00FF000F016100000100015C0AFE
    val VOICE = "FF00FF000F016100000100015C0AFE"


    //蓝牙特性值
    val UUID_SERVICE: UUID = UUID.fromString(uuid16To128("fd00", true))
    val UUID_CHAR_READ_NOTIFY: UUID = UUID.fromString(uuid16To128("fd02", true))
    val UUID_DESC_NOTITY: UUID = UUID.fromString(uuid16To128("fd03", true))
    val UUID_CHAR_WRITE: UUID = UUID.fromString(uuid16To128("fd01", true))

    fun uuid16To128(uuid: String, lower_case: Boolean): String? {
        var uuid_128 = ""
        uuid_128 = if (lower_case) {
            ("0000([0-9a-f][0-9a-f][0-9a-f][0-9a-f])-0000-1000-8000-00805f9b34fb".substring(
                0,
                4
            ) + uuid + "0000([0-9a-f][0-9a-f][0-9a-f][0-9a-f])-0000-1000-8000-00805f9b34fb".substring(
                38
            )).lowercase(
                Locale.getDefault()
            )
        } else {
            ("0000([0-9a-f][0-9a-f][0-9a-f][0-9a-f])-0000-1000-8000-00805f9b34fb".substring(
                0,
                4
            ) + uuid + "0000([0-9a-f][0-9a-f][0-9a-f][0-9a-f])-0000-1000-8000-00805f9b34fb".substring(
                38
            )).uppercase(
                Locale.getDefault()
            )
        }
        return uuid_128
    }
}